// laboratory-common/src/main/java/com/lab/common/PageResult.java
package com.lab.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 分页查询结果封装
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class leavePageResult<T> {
    /**
     * 总记录数
     */
    private Long total;

    /**
     * 当前页数据列表
     */
    private List<T> records;

    /**
     * 总页数
     */
    private Integer totalPages;

    /**
     * 当前页码
     */
    private Integer pageNum;

    /**
     * 每页条数
     */
    private Integer pageSize;

    public static <T> leavePageResult<T> of(Long total, List<T> records, Integer pageNum, Integer pageSize) {
        int totalPages = (int) Math.ceil(total * 1.0 / pageSize);
        return new leavePageResult<>(total, records, totalPages, pageNum, pageSize);
    }
}
